using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMove : MonoBehaviour
{
    // Start is called before the first frame update
    private PlayerJump playerJump;
    private Transform transform;
    private Vector3 defaultScale;
    private Rigidbody2D rb;
    [SerializeField]private float moveSpeed = 4.5f;
    //[SerializeField]private float test = 1;
    public float moveController;
    private Vector2 init ;

    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        transform = GetComponent<Transform>();
        defaultScale = transform.localScale;
        playerJump = GetComponent<PlayerJump>();
        init = new Vector2(0, 0);
    }

    // Update is called once per frame
    void Update()
    {
        MoveController();

    }


    private void MoveController()
    {
        moveController = Input.GetAxis("Horizontal");
        rb.velocity = new Vector2(moveSpeed * moveController + GameManager.Instance.initVelocity.x, rb.velocity.y + GameManager.Instance.initVelocity.y);
        if (moveController > 0.01f)
        {
            transform.localScale = new Vector2(defaultScale.x, defaultScale.y);
        }
        if (moveController < -0.01f)
        {
            transform.localScale = new Vector2(-defaultScale.x, defaultScale.y);
        }
    }
}
